<div id="form<?php echo $uniqid;?>" style="padding-top: 20px">
    <el-form :model="params" method="post" size="small" label-width="140px" @submit.native.prevent label-position="right">
        <el-form-item label="店铺名称：">
            <el-input v-model="params.name" size="small" style="width: 500px"></el-input>
        </el-form-item>
        <el-form-item label="企业名称：">
            <el-input v-model="params.company_name" size="small" style="width: 500px"></el-input>
        </el-form-item>
        <el-form-item label="企业法人姓名：">
            <el-input v-model="params.company_representative_name" size="small" style="width: 500px"></el-input>
        </el-form-item>
        <el-form-item label="联系电话：">
            <el-input v-model="params.phone" size="small" maxlength="11" style="width: 500px"></el-input>
        </el-form-item>
        <el-form-item label="所在区域：">
            <el-select v-model="params.province_id" style="max-width: 140px;" @change="((val)=>{areaChang(1,val)})" size="mini" placeholder="请选择省份" popper-class="zindex_popper">
                <el-option :value='0' :key='0' label="请选择省份"></el-option>
                <el-option
                        v-for="item in prov"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                </el-option>
            </el-select>
            <el-select v-model="params.city_id" style="max-width: 160px;" @change="((val)=>{areaChang(2,val)})" size="mini" placeholder="请选择城市" popper-class="zindex_popper" v-if="params.province_id>0">
                <el-option :value='0' :key='0' label="请选择城市"></el-option>
                <el-option
                        v-for="item in city"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id" v-if="item.pid == params.province_id">
                </el-option>
            </el-select>
            <el-select v-model="params.area_id" style="max-width: 160px;" size="mini" placeholder="请选择区县" popper-class="zindex_popper" v-if="params.province_id>0 && params.city_id>0">
                <el-option :value='0' :key='0' label="请选择区县"></el-option>
                <el-option
                        v-for="item in area"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id" v-if="item.pid == params.city_id">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="详细地址：">
            <el-input v-model="params.address" placeholder="请输入详细地址..，不需要省市县" size="small" style="width: 500px"></el-input>
        </el-form-item>
        <el-form-item label="店铺管理员：">
            <el-tag :key="manager_name"
                    size="medium" v-if="manager_id > 0">
                {{manager_name}}
            </el-tag>
            <el-button class="button-new-tag" size="mini" @click="editManager">{{manager_id > 0?'更换':'设置'}}管理员</el-button>
        </el-form-item>
        <el-form-item label="店铺状态：">
            <el-switch
                    style="display: block"
                    v-model="params.status"
                    active-color="#13ce66"
                    inactive-color="#ff4949"
                    active-text="启用"
                    inactive-text="禁用"
                    :active-value="1"
                    :inactive-value="0">
            </el-switch>
        </el-form-item>
    </el-form>
    <div id="dianpuAdddlg" class="easyui-dialog" style="width:700px; height:580px;" title="信息框" closed="true"></div>
</div>
<script>
    var dianpuAddVm = new Vue({
        el: '#form<?php echo $uniqid;?>',
        data: {
            params: JSON.parse('<?php echo addslashes($dataset);?>'),
            prov: JSON.parse('<?php echo addslashes($prov);?>'),
            city: JSON.parse('<?php echo addslashes($city);?>'),
            area: JSON.parse('<?php echo addslashes($area);?>'),
            manager_name:'',
            manager_id:0,
        },
        mounted(){
            this.init();
        },
        methods: {
            init(){
                
            },
            areaChang:function (type, value) {
                if(type === 1){
                    this.params.city_id = 0;
                    this.params.area_id = 0;
                }
                if(type===2){
                    this.params.area_id = 0;
                }
            },
            editManager: function (){
                $("#dianpuAdddlg").dialog({
                    title: '添加管理员',
                    closed: false,
                    width: 800,
                    height:638,
                    cache: false,
                    href: '/admin/dianpu/getmemberlist',
                    modal: true,
                    buttons: [{
                        text: '确定',
                        id: 'dianpuMasterSubmit',
                        iconCls: 'icon-ok',
                    }, {
                        text: '取消',
                        iconCls: 'icon-no',
                        handler: function () {
                            $("#dianpuAdddlg").dialog('close');
                        }
                    }]
                });
            },
            submit: function(){
                this.params.name = $.trim(this.params.name)
                if(this.params.name.length < 3){
                    $.messager.alert('提示','店铺名称 未填写或字数太少','warning');
                    return;
                }
                this.params.company_name = $.trim(this.params.company_name)
                if(this.params.company_name.length < 3){
                    $.messager.alert('提示','企业名称 未填写或字数太少','warning');
                    return;
                }
                this.params.company_representative_name = $.trim(this.params.company_representative_name)
                if(this.params.company_representative_name.length < 2){
                    $.messager.alert('提示','企业法人姓名 未填写或字数太少','warning');
                    return;
                }
                this.params.phone = $.trim(this.params.phone)
                if(this.params.phone.length < 5){
                    $.messager.alert('提示','联系电话 未填写或字数太少','warning');
                    return;
                }
                if(!this.params.area_id){
                    $.messager.alert('提示','地区 没有选择完整','warning');
                    return;
                }
                this.params.address = $.trim(this.params.address)
                if(this.params.address.length < 2){
                    $.messager.alert('提示','详细地址 没有填写','warning');
                    return;
                }
                if(!this.manager_id){
                    $.messager.alert('提示','未设置管理员','warning');
                    return;
                }
                this.params.member_id = this.manager_id;
                $.post('/admin/dianpu/create', this.params, function(data){
                    if(data.ret===0){
                        $.messager.show({
                            title:'提示',
                            msg:data.msg,
                            timeout:3000,
                            showType:'slide'
                        });
                        $('#<?php echo $uniqid;?>').form('clear');
                        $("#dianpudlg").dialog('close');
                        dianpuReload();
                    }else{
                        $.messager.alert('提示',data.msg,'warning');
                    }
                });
            }
        }
    });
    $('#dianpuAddSubmit').click(function(data){
        dianpuAddVm.submit();
    })
</script>
<style>
    .zindex_popper{
        z-index: 20000 !important;
    }
</style>